package com.monster.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.monster.pojo.CheckGroup;
import com.monster.pojo.CheckItem;
import com.monster.pojo.Member;
import com.monster.pojo.Setmeal;
import com.monster.vo.CheckGroupVO;
import com.monster.vo.SetmealVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface SetMealMapper extends BaseMapper<Setmeal> {
    //添加的时候将重复读删除
    @Delete("DELETE FROM t_setmeal_checkgroup WHERE SETMEAL_ID = #{setmealDTO}")
    Boolean deleteCheckgroupCheckitem(@Param("setmealDTO") Integer setmealDTO);

    //添加
    @Insert("insert into t_setmeal_checkgroup values (#{sid},#{cid})")
    Boolean addCheckgroupSetMeal(@Param("sid") Integer gid, @Param("cid")Integer cid);

    //中间表t_setmeal_checkgroup查询
    @Select("SELECT CHECKGROUP_ID FROM t_setmeal_checkgroup where SETMEAL_ID = #{id}")
    List<Integer> findchegroups(@Param("id") int id);

    //数据回显的时候，图标的地址 以及之前旧的图片名
    @Select("SELECT IMG FROM t_setmeal where ID = #{id}")
    String findImageUrl(@Param("id") Integer id);

    @Select("SELECT id, name,REMARK,AGE,sex,IMG FROM t_setmeal;")
    List<Setmeal> findAllSetmealForH5();

    @Select("SELECT id,name,REMARK,AGE,sex,IMG FROM t_setmeal  where id = #{id}")
    SetmealVO findSetmealById(int id);

    @Select("SELECT id,NAME,REMARK \n" +
            "FROM  t_setmeal_checkgroup tsc , t_checkgroup tc\n" +
            "where tsc.CHECKGROUP_ID = tc.id \n" +
            "and tsc.SETMEAL_ID = #{id}")
    List<CheckGroupVO> findCherkGroupById(@Param("id") int id);

    @Select("SELECT tc.NAME\n" +
            "FROM  t_checkgroup_checkitem tcc , t_checkitem tc\n" +
            "where tcc.CHECKITEM_ID = tc.id \n" +
            "and tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckItemById(@Param("id") int id);

    @Select("SELECT ID, NAME,REMARK,AGE,SEX,IMG FROM t_setmeal where id = #{id}")
    Setmeal findSetMeal(@Param("id") int id);

    @Update("update t_ordersetting set  RESERVATIONS = RESERVATIONS+1  where id = #{setmealId}")
    Boolean updateOrderSetting(@Param("setmealId") Integer setmealId);

    @Select("SELECT count(1) FROM t_ordersetting where NUMBER > RESERVATIONS and  id = #{setmealId}; ")
    Integer isMore(@Param("setmealId") String setmealId);
}
